$(function(){
	//加载所有菜单
	$('#menuPrivilege').fileTree({
		root: 'source',
		script: 'sysRoleAction!queryMenuPrivilege.ac',
		expandEasing: 'easeOutBounce',
		collapseEasing: 'easeOutBounce',
		expandAll: true,
		showLeaf: true,
		showCheckbox: true,
		onlyOneCanChecked: false,
		onlyDeepInCanChecked: true
	});
	
	//提交事件
	$('#submitBtn').click(function(){
		var $n = $('#sysRoleName');
		var $c = $('#menuPrivilege :checkbox[checked]');
		
		if($n.val() == ''){
			jAlert('名称必填');
			return;
		};
		
		function collectData(){
			var a = new Array();
			a.push('sysRole.name=' + $n.val());
			
			//收集所选择的privilege
			if($c.size() > 0){
				var p = new Array();
				$c.each(function(){
					p.push($(this).val());
				});
				
				a.push('privileges=' + p.join(','));
			}
			
			return a.join('&');
		}
		
		$.ajax({
			type:'POST',
			url: 'sysRoleAction!addRole.ac',
			data: collectData(),
			dataType:'json',
			beforeSend:function(){
				jLoading("正在操作，请稍后...");
			},
			success:function(rs){
				if(rs.flag){
					jAlert('操作成功');
				}else{
					jAlert('操作失败:' + rs.msg);
				}
			}
		});
	});
});